package cn.gzsf.csmall.product.controller;

import cn.gzsf.csmall.product.pojo.param.AlbumUpdateInfoParam;
import cn.gzsf.csmall.product.pojo.vo.AlbumListItemVO;
import cn.gzsf.csmall.product.pojo.vo.AlbumStandardVO;
import cn.gzsf.csmall.product.pojo.vo.PageData;
import cn.gzsf.csmall.product.web.JsonResult;
import cn.gzsf.csmall.product.pojo.param.AlbumAddNewParam;
import cn.gzsf.csmall.product.service.IAlbumService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("/album")
@Api(tags = "04.相册管理模块")
@Validated
public class AlbumController {

    @Autowired
    private IAlbumService albumService;

   // @RequestMapping(value = "/add-new",method = RequestMethod.POST)
    @PostMapping("/add-new")
    @ApiOperation("添加相册")
    @ApiOperationSupport(order = 100)
    public JsonResult addNew(@Valid  AlbumAddNewParam albumAddNewParam)  {
        log.debug("开始处理[添加相册]的请求，参数{}",albumAddNewParam);
        albumService.addNew(albumAddNewParam);
        log.debug("处理[添加相册]的请求，完成!");
       /* JsonResult jsonResult = new JsonResult();
        jsonResult.setState(1);
        jsonResult.setMessage("添加成功");*/
        return JsonResult.ok();
    }

    @PostMapping("/delete")
    @ApiOperation("根据id删除相册")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name="albumId",value = "用户ID",required = true,dataType = "long")
    public JsonResult delete(@Range(min=1,message = "根据id删除相册，请提交合法的id值")
                                @RequestParam long albumId){
        log.debug("开始处理【根据ID删除相册】的请求。参数:{}",albumId);
        albumService.delete(albumId);
       return JsonResult.ok();
    }


    @PostMapping("/update")
    @ApiOperation("修改相册")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParam(name="id",value = "相册ID",required = true,dataType = "long")
    public JsonResult update(@RequestParam @Range(min=1,message = "请提交合法的相册id值")  Long id,
                       @Valid  AlbumUpdateInfoParam albumUpdateInfoParam){
         log.debug("开始处理【修改相册详情】业务，参数id:{},相册详情:{}",id,albumUpdateInfoParam);
         albumService.updateInfoById(id,albumUpdateInfoParam);
         return JsonResult.ok();
    }

    @GetMapping("/standard")
    @ApiOperation("根据id查询相册详情")
    @ApiOperationSupport(order = 410)
    @ApiImplicitParam(name="id",value = "相册ID",required = true,dataType = "long")
    public JsonResult getStandardById(@Range(min=1,message = "根据id查询相册失败，请提交合法的id值")
                             @RequestParam long id){
        log.debug("开始处理【根据ID查询相册详情】的请求。参数:{}",id);
        AlbumStandardVO standardVO = albumService.getStandardVO(id);
        return JsonResult.ok(standardVO);
    }



    @GetMapping("/list")
    @ApiOperation("查询相册列表")
    @ApiOperationSupport(order = 420)
    @ApiImplicitParam(name = "page",value = "页码",paramType = "query")
    public JsonResult list(@Range(min = 1,message = "查询相册列表失败,请提供正确的页码值") Integer page){
        log.debug("开始处理【查询相册列表】的请求，页码:{}",page);
        if(page==null||page<1){
            page=1;
        }
        PageData<AlbumListItemVO> pageData = albumService.list(page);
        return JsonResult.ok().setData(pageData);
    }



}
